import os

import numpy as np
import struct
import gzip
import matplotlib.pyplot as plt

def show():
    # waterfall = np.load('test/npy/2023_06_15_15_15_48_origin_stren_data.npy', allow_pickle=False
    npyFilePath = 'C00002_orgin_2025_02_08_10_35_45.npy'
    with open(npyFilePath, 'rb') as sf:
        data_bytes = sf.read()

    byte_fmt, offset = '>III', 12
    bytes_num, row, col = struct.unpack(byte_fmt, data_bytes[:offset])
    npyData = np.frombuffer(gzip.decompress(data_bytes[offset:offset + bytes_num]), dtype='>u1').reshape(row, col)
    plt.imshow(npyData, aspect='auto')
    plt.show()
    # print(npyData.shape)

def read(dir_name:str):
    res=[]
    for path in os.listdir(dir_name):
        if os.path.isfile(path) and path.endswith(".npy"):
            res.append(path)
    return res
def render(files:[str]):
    for f in files:
        with open(f, 'rb') as sf:
            data_bytes = sf.read()
        byte_fmt, offset = '>III', 12
        bytes_num, row, col = struct.unpack(byte_fmt, data_bytes[:offset])
        npyData = np.frombuffer(gzip.decompress(data_bytes[offset:offset + bytes_num]), dtype='>u1').reshape(row, col)
        plt.imshow(npyData, aspect='auto')
        plt.show()

if __name__ == '__main__':
    render(read('..'))
